import {
  Body,
  Controller,
  Get,
  HttpCode,
  HttpStatus,
  Post,
  Req,
} from '@nestjs/common';
import { AuthService } from './auth.service';
// import { AuthGuard } from './auth.guard';
import { Public } from 'src/common/public';

@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @Public()
  @HttpCode(HttpStatus.OK)
  @Post('login')
  signIn(@Body() signInDto: Record<string, any>) {
    console.log(signInDto, 'signInDto');

    return this.authService.signIn(signInDto.username, signInDto.password);
  }

  @Get('profile')
  getProfile(@Req() req: AuthenticatedRequest): User | string {
    console.log(req.user, 'req.user');
    return req.user ? req.user : 'no user';
  }
}
type User = {
  userId: number;
  username: string;
};
interface AuthenticatedRequest extends Request {
  user?: User; // 假设 User 是一个已定义的接口或类型
}
